<template>
    <div class="page" data-page="approveTask" style="z-index: 2;">
        <div class="link-page-nav">
            <a href="#" class="link" @click="$root.backToTab()">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-top">
            <div class="link-page-title" id="link-page-title_{{getNewId}}"></div>
        </div>
        <div class="page-content" id="kalarm_{{getNewId}}" style="padding-top: 0;padding-bottom: 100px;">
            <div id="keyAlarmPic_approveTask_{{getNewId}}" style="margin: 10px 20px;"></div>
            <div style="margin-top:0px;margin-bottom:8px;">
                <div style="padding-left: 20px;font-size: 17px;font-weight: bold;">描述<label
                        style="font-size: 14px">(必填)</label>
                    <i class="iconfont icon-yuyin" style="float:right;margin-right: 20px" id="crTb_inputDetails_{{getNewId}}"></i>
                </div>
                <textarea class="resizable cancle-ios-write" placeholder="简洁明了的描述有利于说明现场情况。尝试用语音输入更便捷" id="desc_{{getNewId}}" name="bjms"></textarea>
                <div style="border-bottom:1px solid #d2d2d2;margin: 0 20px;"></div>
            </div>
            <div class="submitBtn" id="submiBtn_{{getNewId}}" @click="viewBlak_update(2,2)">确定</div>
            <div style="text-align: center;" id="saveBtn_{{getNewId}}">
                <a hred="#" class="returnBtn" @click="viewBlak_update(2,1)">保存，还需继续执行</a>
            </div>
            <div value="通过" class="submitBtn" id="passBtn_{{getNewId}}" @click="viewBlak_update(3,2)">通过</div>
            <div style="text-align: center;" id="returnBtn_{{getNewId}}">
                <a hred="#" class="returnBtn" @click="viewBlak_update(4,2)">驳回</a>
            </div>
        </div>
    </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            var $ = self.$;
            self.status = self.$route.params.status; //状态：1进行中 ，2：审核中，3：已完成，4：已过期，5：已撤回
            self.orgId = self.$route.params.orgId;
            self.taskId = self.$route.params.taskId;
            self.pageName = self.$route.params.pageName;
        },
        data: function () {
            return {
                imageArr: [],
                getNewId: (new Date()).getTime()
            }
        },
        methods: {
            backToRefresh:function(){
            },
            // goBack: function () {
            //     var self = this;
            //     var formData = app.form.convertToData('#kalarm');
            //     var bjms = jQuery.trim(formData.bjms);
            //     if (bjms == "" || self.imageArr.length <= 0) {
            //         app.router.back();
            //     } else {
            //         //是否保存
            //         isSaveData(function () {
            //             //点不保存之后的操作    
            //             app.router.back();
            //         }, function () {
            //             // 点返回继续之后的操作
            //         });
            //     }
            // },
            initBtn: function () {
                var self = this;
                if (self.status == 1) { //进行中 操作提交反馈
                    $("#link-page-title_"+self.getNewId).empty().html(common.transNullundefinedToline("反馈"));
                    $("#submiBtn_"+self.getNewId).show();
                    $("#saveBtn_"+self.getNewId).show();
                    $("#passBtn_"+self.getNewId).hide();
                    $("#returnBtn_"+self.getNewId).hide();
                } else { //审核中 操作通过、驳回
                    $("#link-page-title_"+self.getNewId).empty().html(common.transNullundefinedToline("审核"));
                    $("#submiBtn_"+self.getNewId).hide();
                    $("#saveBtn_"+self.getNewId).hide();
                    $("#passBtn_"+self.getNewId).show();
                    $("#returnBtn_"+self.getNewId).show();
                }
            },
            viewBlak_update: function (nowType, subType) { //提交数据
                var self = this;
                var formData = app.form.convertToData('#kalarm_'+self.getNewId);
                var bjms = jQuery.trim(formData.bjms);
                if (bjms == "") {
                    app.methods.showToastCenter("请填写描述");
                    return;
                }
                common.loading(1);
                Dao.addTempTaskDetail({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    createAccount: userInfor.accountName,
                    picUrls: self.imageArr.toString(),
                    orgId: self.orgId,
                    type: nowType, //类型 1：创建 2：反馈，3：审核，4:驳回，5：撤回，6任务过期
                    description: bjms,
                    submitType: subType, //提交类型 1：表示保存 2:表示提交
                    taskId: self.taskId,
                }, function (data) {
                    common.loading(0);
                    app.methods.showToastCenter("操作成功");
                    app.methods.backToTab();
                });
            },
            initTbPiker: function () {
                var self = this;
                $("#crTb_inputDetails_"+self.getNewId).click(function (e) {
                    //第二个参数是否需要保存语音
                    native.startVoice("desc_"+self.getNewId, false);
                });
            },
            //语音输入回调
            voiceCollectionData: function (voiceStr, componentId) {
                var text = $("#" + componentId).val();
                if (!voiceStr || "" === voiceStr.trim()) {
                    app.methods.showToastCenter("未能识别您说的语音,请重试。");
                } else {
                    $("#" + componentId).val(text + voiceStr);
                }
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                self.initBtn();
                self.initTbPiker();
            },
            pageAfterIn: function () {
                var self = this;
                //初始化上传
                upLoadImagesCompt(jQuery("#keyAlarmPic_approveTask_"+self.getNewId), function (pic, isAdd) {
                    if (isAdd == "add") {
                        self.imageArr.unshift(pic);
                    } else {
                        let index = self.imageArr.indexOf(pic);
                        self.imageArr.splice(index, 1);
                    }
                }, true, null, 'keyAlarmPic_approveTask_container_'+self.getNewId, 'keyAlarmPic_approveTask_pick_'+self.getNewId,'添加图片',true);
            },
            pageBeforeRemove: function (e, page) {

            }
        }
    }
</script>

<style scoped>
    .resizable {
        font-size: 15px;
        width: 100%;
        padding: 18px;
        min-height: 80px;
        max-height: 250px;
    }
    .submitBtn{

        margin: 58px 20px 33px 20px;
        height: 44px;
        line-height: 44px;
        background: rgba(36, 113, 202, 1);
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
        border: 0;
        width: 90%;
        text-align: center;
        font-size: 16px;
        letter-spacing: 2px;
    }
</style>
